package service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import util.Utilities;

import dao.RoomDAO;
import dto.AddressDTO;
import dto.FileListDTO;
import dto.MemberDTO;
import dto.PrivacyDTO;
import dto.PropertyDTO;
import dto.RefundDTO;
import dto.RoomDTO;
import dto.RoomDTO2;

public class RoomManageService {
	private RoomDAO dao;
	public RoomManageService(RoomDAO dao){
		this.dao = dao;
	}
	public void registerRoom(RoomDTO rdto) throws SQLException{
		System.out.println("**********service : "+rdto.getRoomNo());
		if(rdto.getRoomNo()==0){
			rdto.setRoomNo(dao.selectRoomNo());
		}
		rdto.setDescription(Utilities.changeContentForDB(rdto.getDescription()));
		dao.insertRoom(rdto);
	}
	public void registerFile(FileListDTO fdto) throws SQLException{		
		fdto.setFileNo(dao.selectFileNo());		
		dao.insertFile(fdto);
	}
	public ArrayList<AddressDTO> searchAddress(String dong) {
		ArrayList<AddressDTO> list = dao.searchAddress(dong);
		return list;
	}
	public PropertyDTO searchPropertyId(String propertyId) throws SQLException{
		return dao.selectPropertyId(propertyId);
	}
	public PrivacyDTO searchPrivacyId(String privacyId) throws SQLException{
		return dao.selectPrivacyId(privacyId);
	}
	public RefundDTO searchRefundId(String refundId) throws SQLException{
		return dao.selectRefundId(refundId);
	}
	public AddressDTO searchBySeq(String addressId) throws SQLException{
		return dao.selectAddress(addressId);
	}
	public void deleteRoom(int roomNo) throws SQLException{
		dao.removeRoom(roomNo);
	}
	public ArrayList<FileListDTO> searchFileListByRoomNo(int roomNo) throws SQLException{
		return dao.selectFileListByRoomNo(roomNo);
	}
	public RoomDTO searchByRoomNo(int roomNo) throws SQLException{
		return dao.selectByRoomNo(roomNo);
	}
	public ArrayList<RoomDTO> searchByMemberId(String memberId) throws SQLException{
		return dao.selectByMemberId(memberId);
	}
	
	public ArrayList<RoomDTO> searchMyRoomListByMemberId(String memberId) throws SQLException{
		return dao.selectMyRoomListByMemberId(memberId);
	}
	public FileListDTO searchRoomFileByRoomNo(int roomNo) throws SQLException{
		return dao.selectRoomFileByRoomNo(roomNo);
	}
	public RoomDTO searchRoomDetailByRoomNo(int roomNo) throws SQLException{
		return dao.selectRoomDetailByRoomNo(roomNo);
	}
	public void modifyRoomInfoBasic(RoomDTO rdto) throws SQLException{
		rdto.setDescription(Utilities.changeContentForDB(rdto.getDescription()));
		dao.updateRoomInfoBasic(rdto);
	}
	public void modifyRoomInfoadd(RoomDTO rdto) throws SQLException{
		dao.updateRoomInfoAdd(rdto);
		
	}
	public ArrayList<RoomDTO2> allRoomList2() {
		System.out.println("서비스쪽입니다.");
		return dao.allRoomList2();
	}
	public ArrayList allFileList() {
		return dao.allFileList();
	}
	public ArrayList allPrivacyList() {
		return dao.allPrivacyList();
	}
	public ArrayList<RoomDTO> selectByDong(String dong) {		
		RoomDTO2 rdto2 =  new RoomDTO2();
	    rdto2.setDong(dong);
		
		return dao.selectByDong(dong);
		
	}
	public ArrayList<RoomDTO2> selectByadmin(String id) {
		return dao.selectByadmin(id);
	}
	public void deleteFile(String filename) {
		dao.deleteFile(filename);
		
	}
	public String randomImage() {		
		return dao.randomImage();	
				
	}
	public ArrayList<RoomDTO> selectByCity(String dong) {
		RoomDTO2 rdto2 =  new RoomDTO2();
	    rdto2.setDong(dong);
	    return dao.selectByCity(dong);
	}
	public ArrayList<RoomDTO> selectBygugun(String dong) {
		RoomDTO2 rdto2 =  new RoomDTO2();
	    rdto2.setDong(dong);
	    return dao.selectBygugun(dong);
	}
	//방목록과 후기목록 모두 삭제하게 함
	public void delete(int roomNo) {
		dao.delete(roomNo);
		
	}
	public String countmember() {
		return dao.countmember();
	}
	public String countroom() {
		return dao.countroom();
	}
}
